import redis
import json

task_id = 1
r = redis.Redis(host='localhost', port=6379, db=0)
task_key = f"{task_id}:"

task_keys = r.keys(f"{task_key}*")
result = []
for key in task_keys:
    key_str = key.decode('utf-8')
    rank = int(key_str.split(":")[-1])

    data = r.hgetall(key)
    item = {
        "title": data.get(b"title", b"").decode('utf-8'),
        "hot_count": data.get(b"hot_count").decode('utf-8'),
        "rank": rank
    }
    result.append(item)
result.sort(key=lambda x: x["rank"])
print(result)
